Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Does it make a difference (speed-wise) if i pick an object by index or via „find“ from an array?

The title pretty much descripes it. I got an array of days, sorted by the date. So the 1th of the month would be month[0].

When i pick these days in a loop, would it be faster to do this by

month.find(day => day.date === date)

Or

month[date-1]

Thank you for help :)

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

It does make a difference. When you use a direct index to look up the associated item, the computational complexity is O(1) - the engine just needs to look at the item at that single index and it finds it. But when you use .find, you go through every element of the array and call the callback on each one, only stopping once the found object passes the test.

That said, you'd only notice a difference if you were doing this sort of thing with a huge array and/or in a very tight loop. The difference will be utterly imperceptible most of the time.

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda